//
//  ZH_CommodityTableViewCell.m
//  ChangeMerchants
//
//  Created by zhangliwen on 2018/9/21.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_CommodityTableViewCell.h"
@interface ZH_CommodityTableViewCell()
@property (nonatomic,weak)UIImageView *pickImage;
@property (nonatomic,weak)UILabel *titlelabel;
@property (nonatomic,weak)UILabel *contentlabel;
@property (nonatomic,weak)UILabel *priceLabel;
@property (nonatomic,weak)UIButton *stateButton;
@property (nonatomic,weak)UIButton *skillButton;
@end
@implementation ZH_CommodityTableViewCell

///创建
+ (instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_CommodityTableViewCell";
    ZH_CommodityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_CommodityTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

///初始化
-(void)initDefault
{
    [self unShowClickEffect];
    self.bottomShortLineImage.hidden = NO;
}
- (void)loadSubviewConstraints{
    [self.pickImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(10));
        make.left.equalTo(self.contentView).offset(FITSCALE(10));
        make.width.mas_equalTo(FITSCALE(81));
        make.height.mas_equalTo(FITSCALE(81));
        make.bottom.equalTo(self.contentView).offset(FITSCALE(-14));
    }];
    [self.titlelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.pickImage);
        make.left.equalTo(self.pickImage.mas_right).offset(FITSCALE(12));
        make.right.equalTo(self.contentView).offset(FITSCALE(-60));
    }];
    [self.contentlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titlelabel.mas_bottom).offset(FITSCALE(10));
        make.left.equalTo(self.titlelabel);
        make.right.equalTo(self.contentView).offset(FITSCALE(-10));
    }];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titlelabel);
        make.bottom.equalTo(self.contentView).offset(FITSCALE(-20));
    }];
    [self.stateButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView).offset(FITSCALE(-14));
        make.right.equalTo(self.contentView).offset(FITSCALE(-10));
    }];
//    [self.skillButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.contentView).offset(FITSCALE(8));
//        make.right.equalTo(self.contentView).offset(FITSCALE(-10));
//        make.width.mas_equalTo(FITSCALE(37));
//        make.height.mas_equalTo(FITSCALE(19));
//    }];
}
- (void)updataUI:(NSMutableDictionary *)data{
    if (data) {
        [self.pickImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data[@"cover_img"]]] placeholderImage:nil];
        self.titlelabel.text = data[@"name"];
        self.contentlabel.text = data[@"describe"];
        self.priceLabel.text = [NSString stringWithFormat:@"￥%@",data[@"show_price"]];
    }
}
#pragma mark - getter,setter
- (UIImageView *)pickImage{
    if (!_pickImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@""];
        image.backgroundColor = [UIColor redColor];
        image.layer.cornerRadius = FITSCALE(3);
        image.layer.masksToBounds = YES;
        image.clipsToBounds = YES;
        [self.contentView addSubview:_pickImage = image];
    }
    return _pickImage;
}
- (UILabel *)titlelabel{
    if (!_titlelabel) {
        UILabel *label = [UILabel createLabelWithText:@"商品名称..." font:kFontSize_28];
        [self.contentView addSubview:_titlelabel = label];
    }
    return _titlelabel;
}
- (UILabel *)contentlabel{
    if (!_contentlabel) {
        UILabel *label = [UILabel createLabelWithText:@"商品描述, 商品描述, 商品描述" font:kFontSize_24];
        [label setNumberOfLines:2];
        [self.contentView addSubview:_contentlabel = label];
    }
    return _contentlabel;
}
- (UILabel *)priceLabel{
    if (!_priceLabel) {
        UILabel *label = [UILabel createLabelWithText:@"￥100" font:kFontSize_30];
        label.textColor = [UIColor colorWithHexString:@"#F0302F"];
        [self.contentView addSubview:_priceLabel = label];
    }
    return _priceLabel;
}
- (UIButton *)stateButton{
    if (!_stateButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"" target:self action:nil];
        [button setImage:[UIImage imageNamed:@"icon_goshop"] forState:UIControlStateNormal];
        [self.contentView addSubview:_stateButton = button];
    }
    return _stateButton;
}
- (UIButton *)skillButton{
    if (!_skillButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"秒杀" target:self action:nil];
        button.backgroundColor = [UIColor colorWithHexString:@"#FB7716"];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(9);
        button.titleLabel.font = kFontSize_22;
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        [self.contentView addSubview:_skillButton = button];
    }
    return _skillButton;
}
@end
